package com.fulei.device;

import com.bjfl.saleManager.util.LogUtil;
import com.fulei.logic.CoorDinateGood;

public class GoodsDevice
{
  private String deviceType;
  private String comNo;
  private String baudRate;
  
  public GoodsDevice(String devType, String com, String brn)
  {
    this.deviceType = devType;
    this.comNo = com;
    this.baudRate = brn;
  }
  
  public int goodsReset()
  {
    int return_data = 0;
    try
    {
      if ("GOODS2".equals(this.deviceType))
      {
        CoorDinateGood.comNo = this.comNo;
        CoorDinateGood.baudRate = this.baudRate;
        return_data = CoorDinateGood.ResetGoods();
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("货道复位:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int goodsReset(int addr)
  {
    int return_data = 0;
    try
    {
      if ("GOODS2".equals(this.deviceType))
      {
        CoorDinateGood.comNo = this.comNo;
        CoorDinateGood.baudRate = this.baudRate;
        return_data = CoorDinateGood.ResetGoods(addr);
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("货道复位:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int goodsStatus()
  {
    int return_data = 0;
    try
    {
      if ("GOODS2".equals(this.deviceType))
      {
        CoorDinateGood.comNo = this.comNo;
        CoorDinateGood.baudRate = this.baudRate;
        return_data = CoorDinateGood.ShipMentStatus();
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("货道状态:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int goodsStatus(int addr)
  {
    int return_data = 0;
    try
    {
      if ("GOODS2".equals(this.deviceType))
      {
        CoorDinateGood.comNo = this.comNo;
        CoorDinateGood.baudRate = this.baudRate;
        return_data = CoorDinateGood.ShipMentStatus(addr);
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("货道状态:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int CoorDinateCaseGood(int YLine, int XLine)
  {
    int return_data = 0;
    try
    {
      if ("GOODS2".equals(this.deviceType))
      {
        CoorDinateGood.comNo = this.comNo;
        CoorDinateGood.baudRate = this.baudRate;
        return_data = CoorDinateGood.CoorDinateCaseGood(YLine, XLine);
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("电机测试后置和左右电机异常:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int CoorDinateCaseGood(int addr, int YLine, int XLine)
  {
    int return_data = 0;
    try
    {
      if ("GOODS2".equals(this.deviceType))
      {
        CoorDinateGood.comNo = this.comNo;
        CoorDinateGood.baudRate = this.baudRate;
        return_data = CoorDinateGood.CoorDinateCaseGood(addr, YLine, XLine);
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("电机测试后置和左右电机异常:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int PreposeMotorCase(int ZLine)
  {
    int return_data = 0;
    try
    {
      if ("GOODS2".equals(this.deviceType))
      {
        CoorDinateGood.comNo = this.comNo;
        CoorDinateGood.baudRate = this.baudRate;
        return_data = CoorDinateGood.PreposeMotorCase(ZLine);
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("电机测试前置电机异常:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int PreposeMotorCase(int addr, int ZLine)
  {
    int return_data = 0;
    try
    {
      if ("GOODS2".equals(this.deviceType))
      {
        CoorDinateGood.comNo = this.comNo;
        CoorDinateGood.baudRate = this.baudRate;
        return_data = CoorDinateGood.PreposeMotorCase(addr, ZLine);
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("电机测试前置电机异常:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int goodsSellCase(int ZLine, int YLine, int XLine)
  {
    int return_data = 0;
    try
    {
      if ("GOODS2".equals(this.deviceType))
      {
        CoorDinateGood.comNo = this.comNo;
        CoorDinateGood.baudRate = this.baudRate;
        return_data = CoorDinateGood.goodsSellCase(ZLine, YLine, XLine);
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("出货指令异常:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int goodsSellCase(int addr, int ZLine, int YLine, int XLine)
  {
    int return_data = 0;
    try
    {
      if ("GOODS2".equals(this.deviceType))
      {
        CoorDinateGood.comNo = this.comNo;
        CoorDinateGood.baudRate = this.baudRate;
        return_data = CoorDinateGood.goodsSellCase(addr, ZLine, YLine, XLine);
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("出货指令异常:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int CoorDinateHome(int YLine, int XLine)
  {
    int return_data = 0;
    try
    {
      if ("GOODS2".equals(this.deviceType))
      {
        CoorDinateGood.comNo = this.comNo;
        CoorDinateGood.baudRate = this.baudRate;
        return_data = CoorDinateGood.CoorDinateHome(YLine, XLine);
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("后置和左右电机归位异常:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int CoorDinateHome(int addr, int YLine, int XLine)
  {
    int return_data = 0;
    try
    {
      if ("GOODS2".equals(this.deviceType))
      {
        CoorDinateGood.comNo = this.comNo;
        CoorDinateGood.baudRate = this.baudRate;
        return_data = CoorDinateGood.CoorDinateHome(addr, YLine, XLine);
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("后置和左右电机归位异常:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int PreposeMotorHome(int ZLine)
  {
    int return_data = 0;
    try
    {
      if ("GOODS2".equals(this.deviceType))
      {
        CoorDinateGood.comNo = this.comNo;
        CoorDinateGood.baudRate = this.baudRate;
        return_data = CoorDinateGood.PreposeMotorHome(ZLine);
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("前置电机归位异常:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int PreposeMotorHome(int addr, int ZLine)
  {
    int return_data = 0;
    try
    {
      if ("GOODS2".equals(this.deviceType))
      {
        CoorDinateGood.comNo = this.comNo;
        CoorDinateGood.baudRate = this.baudRate;
        return_data = CoorDinateGood.PreposeMotorHome(addr, ZLine);
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("前置电机归位异常:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int pocketSellCase()
  {
    int return_data = 0;
    try
    {
      if ("GOODS2".equals(this.deviceType))
      {
        CoorDinateGood.comNo = this.comNo;
        CoorDinateGood.baudRate = this.baudRate;
        return_data = CoorDinateGood.pocketSellCase();
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("出袋指令异常:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int pocketStatus()
  {
    int return_data = 0;
    try
    {
      if ("GOODS2".equals(this.deviceType))
      {
        CoorDinateGood.comNo = this.comNo;
        CoorDinateGood.baudRate = this.baudRate;
        return_data = CoorDinateGood.pocketStatus();
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("查询食品袋状态异常:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int pocketMotorForward(int times)
  {
    int return_data = 0;
    try
    {
      if ("GOODS2".equals(this.deviceType))
      {
        CoorDinateGood.comNo = this.comNo;
        CoorDinateGood.baudRate = this.baudRate;
        return_data = CoorDinateGood.pocketMotorForward(times);
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("电机正转异常:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int pocketMotorReversal(int times)
  {
    int return_data = 0;
    try
    {
      if ("GOODS2".equals(this.deviceType))
      {
        CoorDinateGood.comNo = this.comNo;
        CoorDinateGood.baudRate = this.baudRate;
        return_data = CoorDinateGood.pocketMotorReversal(times);
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("电机反转异常:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int pocketMotorSpeed(int times)
  {
    int return_data = 0;
    try
    {
      if ("GOODS2".equals(this.deviceType))
      {
        CoorDinateGood.comNo = this.comNo;
        CoorDinateGood.baudRate = this.baudRate;
        return_data = CoorDinateGood.pocketMotorSpeed(times);
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("调节电机速度指令异常:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int pocketReset()
  {
    int return_data = 0;
    try
    {
      if ("GOODS2".equals(this.deviceType))
      {
        CoorDinateGood.comNo = this.comNo;
        CoorDinateGood.baudRate = this.baudRate;
        return_data = CoorDinateGood.pocketReset();
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("食品袋复位异常:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
}
